package com.pzb.goods.service.impl;

import java.util.List;

import com.pzb.goods.domain.GdGoodsAttributeOption;
import com.pzb.goods.service.IGdGoodsAttributeOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.pzb.goods.mapper.GdGoodsAttributeMapper;
import com.pzb.goods.domain.GdGoodsAttribute;
import com.pzb.goods.service.IGdGoodsAttributeService;

/**
 * 商品属性Service业务层处理
 * 
 * @author Mr_Wu
 * @date 2021-11-29
 */
@Service
public class GdGoodsAttributeServiceImpl implements IGdGoodsAttributeService 
{
    @Autowired
    private GdGoodsAttributeMapper gdGoodsAttributeMapper;
    @Autowired
    private IGdGoodsAttributeOptionService goodsAttributeOptionService;
    /**
     * 查询商品属性
     * 
     * @param id 商品属性主键
     * @return 商品属性
     */
    @Override
    public GdGoodsAttribute selectGdGoodsAttributeById(Long id)
    {
        return gdGoodsAttributeMapper.selectGdGoodsAttributeById(id);
    }

    /**
     * 查询商品属性列表
     * 
     * @param gdGoodsAttribute 商品属性
     * @return 商品属性
     */
    @Override
    public List<GdGoodsAttribute> selectGdGoodsAttributeList(GdGoodsAttribute gdGoodsAttribute)
    {
        List<GdGoodsAttribute> attributeList=gdGoodsAttributeMapper.selectGdGoodsAttributeList(gdGoodsAttribute);
        for (GdGoodsAttribute goodsAttribute : attributeList) {
            if ("0".equals(goodsAttribute.getType())) {
                GdGoodsAttributeOption q = new GdGoodsAttributeOption();
                q.setAttributeId(goodsAttribute.getId());
                List<GdGoodsAttributeOption> optionList = goodsAttributeOptionService.selectGdGoodsAttributeOptionList(q);
                goodsAttribute.setOptionList(optionList);
            }
        }
        return attributeList;
    }

    /**
     * 新增商品属性
     * 
     * @param gdGoodsAttribute 商品属性
     * @return 结果
     */
    @Override
    public int insertGdGoodsAttribute(GdGoodsAttribute gdGoodsAttribute)
    {
        return gdGoodsAttributeMapper.insertGdGoodsAttribute(gdGoodsAttribute);
    }

    /**
     * 修改商品属性
     * 
     * @param gdGoodsAttribute 商品属性
     * @return 结果
     */
    @Override
    public int updateGdGoodsAttribute(GdGoodsAttribute gdGoodsAttribute)
    {
        return gdGoodsAttributeMapper.updateGdGoodsAttribute(gdGoodsAttribute);
    }

    /**
     * 批量删除商品属性
     * 
     * @param ids 需要删除的商品属性主键
     * @return 结果
     */
    @Override
    public int deleteGdGoodsAttributeByIds(Long[] ids)
    {
        return gdGoodsAttributeMapper.deleteGdGoodsAttributeByIds(ids);
    }

    /**
     * 删除商品属性信息
     * 
     * @param id 商品属性主键
     * @return 结果
     */
    @Override
    public int deleteGdGoodsAttributeById(Long id)
    {
        return gdGoodsAttributeMapper.deleteGdGoodsAttributeById(id);
    }
}
